package controller;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.tagext.TryCatchFinally;

import common.PageReturn;
import dao.ManagerDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;


import common.ImgUtil;
import common.TableReturn;
import pojo.*;
import service.*;

@Controller
@RequestMapping("manager")
public class ManagerController {

    @Autowired
    private ManagerServiceI managerServiceI;
    @Autowired
    private EssayServiceI essayServiceI;
    @Autowired
    private UserServiceI userServiceI;
    @Autowired
    private MessageServiceI messageServiceI;
    @Autowired
    private CollectionServiceI collectionServiceI;
    @Autowired
    private AttentionServiceI attentionServiceI;
    @Autowired
    private ObtainServiceI obtainServiceI;
    @Autowired
    private ManagerDao managerDao;

    /**
     * @throws
     * @Title: logincode
     * @Description: TODO(登录验证码)
     * @param: @param request
     * @param: @param response
     * @param: @throws IOException
     * @return: void
     */
    @RequestMapping("logincode")
    public void logincode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        char[] array = ImgUtil.getStr();
        request.getSession().setAttribute("loginvercode", String.valueOf(array));
        BufferedImage image = ImgUtil.getImage(array);
        ImageIO.write(image, "JPG", response.getOutputStream());
    }

    /**
     * @throws
     * @Title: login
     * @Description: TODO(登录验证)
     * @param: @param request
     * @param: @return
     * @return: String
     */
    @RequestMapping("login")
    @ResponseBody
    public String login(HttpServletRequest request) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String vercode = request.getParameter("vercode");
        String check_vercode = (String) request.getSession().getAttribute("loginvercode");// 获取session的验证码
        if (!vercode.toLowerCase().equals(check_vercode.toLowerCase())) {
            return "wrongvercode";// 验证码错误
        } else {
            boolean bool = managerServiceI.login(username, password, request);
            if (bool) {
                return "success";
            } else
                return "false";
        }
    }

    /**
     * 　　* @param
     * 　　* @return
     * 　　* @author：千夜
     * 　　* @date 2019/4/24 11:14
     * 　 * @description: TODO(登录成功跳转)
     */
    @RequestMapping("successLoginRedirect")
    public ModelAndView successLoginRedirect(HttpSession session, ModelAndView modelAndView) {
        Manager manager = (Manager) session.getAttribute("manager");
        if (manager != null) {
            modelAndView.setViewName("/community/jsp/manager/managerIndex");
        } else {
            modelAndView.addObject("manager", manager);
            modelAndView.setViewName("/community/jsp/manager/managerIndex");
        }
        return modelAndView;
    }

    /**
     * 　　* @param []
     * 　　* @return java.lang.String
     * 　　* @author：千夜
     * 　　* @date 2019/4/24 11:15
     * 　 * @description: TODO(管理者消息页的跳转)
     */
    @RequestMapping("messageredirect")
    public String messageredirect() {
        return "/community/jsp/manager/managerMessage";
    }

    /**
     * 　　* @param
     * 　　* @return
     * 　　* @author：千夜
     * 　　* @date 2019/4/24 11:15
     * 　 * @description: TODO(登出跳转，销毁session)
     */
    @RequestMapping("logout")
    @ResponseBody
    public String logout(HttpSession session) {
        session.invalidate();
        return "success";
    }

    /**
     * @throws
     * @Title: essayredirect
     * @Description: TODO(文章管理页的跳转)
     * @param: @return
     * @return: String
     */
    @RequestMapping("essayredirect")
    public String essayredirect() {
        return "/community/jsp/manager/userEssay";
    }

    /**
     * 　　* @param null
     * 　　* @return string
     * 　　* @author：千夜
     * 　　* @date 2019/4/27 11:14
     * 　 * @description: TODO(已审核文章页面的跳转)
     */
    @RequestMapping("auditingRedirect")
    public String auditingRedirect() {
        return "/community/jsp/manager/essayAuditing";
    }

    /**
     * 　　* @param null
     * 　　* @return string
     * 　　* @author：千夜
     * 　　* @date 2019/4/27 11:14
     * 　 * @description: TODO(未审核文章页面的跳转)
     */
    @RequestMapping("UnAuditingRedirect")
    public String UnAuditingRedirect() {
        return "/community/jsp/manager/essayUnAuditing";
    }


    /**
     * 　　* @param
     * 　　* @return
     * 　　* @author：千夜
     * 　　* @date 2019/4/24 14:14
     * 　 * @description: TODO(用户管理页的跳转)
     */
    @RequestMapping("userredirect")
    public String userredirect() {
        return "/community/jsp/manager/user";
    }

    @RequestMapping("userInformationRedirect")
    public String userInformationRedirect() {
        return "/community/jsp/manager/userInformation";
    }


    /**
     * 　　* @param
     * 　　* @return
     * 　　* @author：千夜
     * 　　* @date 2019/4/24 14:14
     * 　 * @description: TODO（主页的跳转）
     */
    @RequestMapping("mainredirect")
    public ModelAndView mainredirect(ModelAndView modelAndView) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置时间格式
        String today = df.format(new Date());//今日日期
        int MessageCount = managerDao.SelectTodayMessageCount();//管理员消息总数
        int TodayEssayCount = managerDao.SelectTodayEssayCount(today);//今日发布文章总数
        int AllDownloadEssayCount = managerDao.SelectAllDownloadEssayCount();//所有下载帖总数
        int TodayDownloadEssayCount = managerDao.SelectTodayDownloadEssayCount(today);//今日发布下载贴总数
        int TodayCommonEssayCount = managerDao.SelectTodayCommonEssayCount(today);//今日发布普通贴的数量
        int AllCommonEssayCount = managerDao.SelectAllCommonEssayCount();//所有普通帖子的数量
        int EssayUnAuditingCount = managerDao.SelectEssayUnAuditingCount();//未审核文章总数
        int AllEssayCount = managerDao.SelectAllEssayCount();//文章总数
        modelAndView.addObject("MessageCount", MessageCount);
        modelAndView.addObject("TodayEssayCount", TodayEssayCount);
        modelAndView.addObject("AllDownloadEssayCount", AllDownloadEssayCount);
        modelAndView.addObject("TodayDownloadEssayCount", TodayDownloadEssayCount);
        modelAndView.addObject("TodayCommonEssayCount", TodayCommonEssayCount);
        modelAndView.addObject("AllCommonEssayCount", AllCommonEssayCount);
        modelAndView.addObject("EssayUnAuditingCount", EssayUnAuditingCount);
        modelAndView.addObject("AllEssayCount", AllEssayCount);
        modelAndView.setViewName("/community/jsp/manager/main");
        return modelAndView;
    }

    /**
     * @throws
     * @Title: successLogin
     * @Description: TODO(登录成功跳转)
     * @param: @param modelAndView
     * @param: @return
     * @return: ModelAndView
     */
    @RequestMapping("managerIndex")
    @ResponseBody
    public Map<String, Object> managerIndex(@RequestParam String page, @RequestParam String limit) {
        /***********************分页准备***********************************/
        Integer currentPage = Integer.valueOf(page).intValue();
        Integer limitNumber = Integer.valueOf(limit).intValue();
        Page page1 = new Page();
        page1.setCurrentPage(currentPage);
        page1.setLimitNumber(limitNumber);
        /********************************************************/
        List<MessageUserEssay> list = managerServiceI.FindAllMessage(page1);
        TableReturn tableReturn = new TableReturn();
        Map<String, Object> map = tableReturn.returnData(list);
        return map;
    }

    /**
     * 　　* @param request
     * 　　* @return map
     * 　　* @author：千夜
     * 　　* @date 2019/4/24 14:14
     * 　 * @description: TODO(文章管理页的table,显示全部文章)
     */
    @RequestMapping("userEssay")
    @ResponseBody
    public Map<String, Object> userEssay(HttpServletRequest request, @RequestParam String page, @RequestParam String limit) {
        /***********************分页准备***********************************/
        Integer currentPage = Integer.valueOf(page).intValue();
        Integer limitNumber = Integer.valueOf(limit).intValue();
        Page page1 = new Page();
        page1.setCurrentPage(currentPage);
        page1.setLimitNumber(limitNumber);
        /********************************************************/
        List<EssayAndUser> list = essayServiceI.FindManagerViewEssay(page1);
        Integer TotalCount = managerServiceI.FindAllEssayCount();
        TableReturn tableReturn = new TableReturn();
        Map<String, Object> map = tableReturn.returnEssayData(TotalCount, list);
        return map;
    }

    /**
     * 　　* @param request
     * 　　* @return map
     * 　　* @author：千夜
     * 　　* @date 2019/4/29 20:30
     * 　 * @description: TODO:全部文章的查询
     */
    @RequestMapping("userEssaySelectAll")
    @ResponseBody
    public Map<String, Object> userEssaySelectAll(HttpServletRequest request, @RequestParam String page, @RequestParam String limit) {
        String essayId = request.getParameter("essayId");
        String title = request.getParameter("title");
        if (essayId != null && essayId != "") {//根据ID查询
            Integer essayId1 = Integer.valueOf(essayId).intValue();
            List<EssayAndUser> list = managerServiceI.FindAllByEssayId(essayId1);
            Integer TotalCount = list.size();
            TableReturn tableReturn = new TableReturn();
            Map<String, Object> map = tableReturn.returnEssayData(TotalCount, list);
            return map;
        } else if (essayId == null || essayId == "") {//id为空，证明不是根据ID查询
            /*************************分页部分*********************************/
            Integer currentPage = Integer.valueOf(page).intValue();//获取当前页
            Integer limitNumber = Integer.valueOf(limit).intValue();//获取每页条数
            Page page1 = new Page();
            page1.setCurrentPage(currentPage);
            page1.setLimitNumber(limitNumber);//注入page实体
            /*******************************************************************/
            List<EssayAndUser> list = managerServiceI.FindAllByTitle(title, page1);//根据标题查询
            Integer TotalCount = managerServiceI.FindByTitleCount(title);
            TableReturn tableReturn = new TableReturn();
            Map<String, Object> map = tableReturn.returnEssayData(TotalCount, list);//返回layui/tabel规定格式数据
            return map;
        } else
            return null;
    }

    /**
     * 　　* @param request
     * 　　* @return
     * 　　* @author：千夜
     * 　　* @date 2019/4/25 19:54
     * 　 * @description: TODO(根据审核与否显示/表格初始渲染数据)
     */
    @RequestMapping("userEssayAuditing")
    @ResponseBody
    public Map<String, Object> userEssayUnAuditing(HttpServletRequest request, @RequestParam String page, @RequestParam String limit) {
        String flag = request.getParameter("flag");
        /*************************分页部分*********************************/
        Integer currentPage = Integer.valueOf(page).intValue();//获取当前页
        Integer limitNumber = Integer.valueOf(limit).intValue();//获取每页条数
        Page page1 = new Page();
        page1.setCurrentPage(currentPage);
        page1.setLimitNumber(limitNumber);//注入page实体
        /*******************************************************************/
        List<EssayAndUser> list = managerServiceI.FindByAuditing(flag, page1);
        Integer TotalCount;
        if ("1".equals(flag)) {
            TotalCount = managerServiceI.FindAuditingEssayCount();//已审核文章数量
        } else {
            TotalCount = managerServiceI.FindUnAuditingEssayCount();//未审核文章数量
        }
        TableReturn tableReturn = new TableReturn();
        Map<String, Object> map = tableReturn.returnEssayData(TotalCount, list);
        return map;
    }

    /**
     * 　　* @param request
     * 　　* @return map
     * 　　* @author：千夜
     * 　　* @date 2019/4/29 20:29
     * 　 * @description: TODO:根据文章Id精准查询以及文章标题模糊查询
     */
    @RequestMapping("userEssaySelect")
    @ResponseBody
    public Map<String, Object> userEssaySelect(HttpServletRequest request, @RequestParam String page, @RequestParam String limit) {
        String flag = request.getParameter("flag");
        String essayId = request.getParameter("essayId");
        String title = request.getParameter("title");
        if (essayId != null && essayId != "") {//根据ID查询
            Integer essayId1 = Integer.valueOf(essayId).intValue();
            List<EssayAndUser> list = managerServiceI.FindByEssayId(essayId1, flag);
            Integer TotalCount = list.size();//数量设置为list.size()
            TableReturn tableReturn = new TableReturn();
            Map<String, Object> map = tableReturn.returnEssayData(TotalCount, list);
            return map;
        } else if (essayId == null || essayId == "") {
            /*************************分页部分*********************************/
            Integer currentPage = Integer.valueOf(page).intValue();//获取当前页
            Integer limitNumber = Integer.valueOf(limit).intValue();//获取每页条数
            Page page1 = new Page();
            page1.setCurrentPage(currentPage);
            page1.setLimitNumber(limitNumber);//注入page实体
            /*******************************************************************/
            List<EssayAndUser> list = managerServiceI.FindByTitle(title, flag, page1);
            Integer TotalCount;
            if ("1".equals(flag)) {
                TotalCount = managerServiceI.FindByTitleCountAuditing(title);
            } else {
                TotalCount = managerServiceI.FindByTitleCountUnAuditing(title);
            }
            TableReturn tableReturn = new TableReturn();
            Map<String, Object> map = tableReturn.returnEssayData(TotalCount, list);
            return map;
        } else
            return null;
    }

    /**
     * 　　* @param
     * 　　* @author：千夜
     * 　　* @date 2019/4/24 14:20
     * 　 * @description: TODO:用户页的table
     */
    @RequestMapping("user")
    @ResponseBody
    public Map<String, Object> user(@RequestParam String page, @RequestParam String limit) {
        /*************************分页部分*********************************/
        Integer currentPage = Integer.valueOf(page).intValue();//获取当前页
        Integer limitNumber = Integer.valueOf(limit).intValue();//获取每页条数
        Page page1 = new Page();
        page1.setCurrentPage(currentPage);
        page1.setLimitNumber(limitNumber);//注入page实体
        /*******************************************************************/
        List<User> list = userServiceI.FindAllUser(page1);
        Integer TotalCount = managerServiceI.FindUserCount();
        System.out.println(TotalCount);
        TableReturn tableReturn = new TableReturn();
        Map<String, Object> map = tableReturn.returnUserData(TotalCount, list);
        return map;
    }

    /**
     * 　　* @param request
     * 　　* @return map
     * 　　* @author：千夜
     * 　　* @date 2019/4/29 20:38
     * 　 * @description: TODO:管路员对用户的搜索
     */
    @RequestMapping("userSelect")
    @ResponseBody
    public Map<String, Object> userSelect(HttpServletRequest request, @RequestParam String page, @RequestParam String limit) {
        String userId = request.getParameter("userId");
        String username = request.getParameter("username");
        if (userId != null && userId != "") {
            Integer userId1 = Integer.valueOf(userId).intValue();
            List<User> list = userServiceI.FindByUserId(userId1);
            Integer TotalCount = list.size();
            TableReturn tableReturn = new TableReturn();
            Map<String, Object> map = tableReturn.returnUserData(TotalCount, list);
            return map;
        } else if (userId == null || userId == "") {
            /*************************分页部分*********************************/
            Integer currentPage = Integer.valueOf(page).intValue();//获取当前页
            Integer limitNumber = Integer.valueOf(limit).intValue();//获取每页条数
            Page page1 = new Page();
            page1.setCurrentPage(currentPage);
            page1.setLimitNumber(limitNumber);//注入page实体
            /*******************************************************************/
            List<User> list = userServiceI.FindUserByText(username, page1);
            Integer TotalCount = managerServiceI.FindUserByNameCount(username);
            System.out.println(TotalCount);
            TableReturn tableReturn = new TableReturn();
            Map<String, Object> map = tableReturn.returnUserData(TotalCount, list);
            return map;
        } else
            return null;
    }

    /**
     * 　　* @param request
     * 　　* @return
     * 　　* @author：千夜
     * 　　* @date 2019/4/25 16:09
     * 　 * @description: TODO:文章通过审核
     */
    @RequestMapping("passEssay")
    @ResponseBody
    public String passEssay(HttpServletRequest request) {
        Integer essayId = Integer.valueOf(request.getParameter("essayId")).intValue();
        int j = essayServiceI.FindEssay(essayId).getAuditing();
        if (j == 1) {
            return "alreadyAuditing";
        } else {
            Integer auditing = 1;
            Essay essay = new Essay();
            essay.setEssayId(essayId);
            essay.setAuditing(auditing);
            int i = essayServiceI.UpdateEssayPtcvr(essay);
            if (i > 0) {
                return "success";
            } else
                return "false";
        }
    }


    /**
     * 　　* @param request
     * 　　* @return String
     * 　　* @author：千夜
     * 　　* @date 2019/4/27 10:29
     * 　 * @description: TODO:敏感文章，删除，返回消息给发布者,同时删除此条消息
     */
    @RequestMapping("DeleteEssay")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public String DeleteEssay(HttpServletRequest request) {
        Integer essayId = Integer.valueOf(request.getParameter("essayId")).intValue();
        String managerMessage = request.getParameter("messageId");
        Integer messageId = 0;
        if (managerMessage != null && managerMessage != "") {
            messageId = Integer.valueOf(managerMessage).intValue();
        }
        String context = request.getParameter("content");
        Integer recieveUserId = essayServiceI.FindEssay(essayId).getUserId();
        Integer sendUserId = -1;
        Integer flag = 4;
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置时间格式
        String messageDate = df.format(new Date());
        try {
            messageServiceI.MakeMessageByManager(sendUserId, recieveUserId, flag, essayId, context);//生成消息通知发布者
            essayServiceI.DeleteEssay(essayId);//删除文章
            if (messageId != 0) {
                managerServiceI.RemoveMessage(messageId);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "false";
        }
        return "success";
    }

    /**
     * 　　* @param request
     * 　　* @author：千夜
     * 　　* @date 2019/4/25 16:54
     * 　 * @description: TODO:删除管理员的消息/管理员不想看时直接删除
     */
    @RequestMapping("deleteMessage")
    @ResponseBody
    public String deleteMessage(HttpServletRequest request) {
        Integer managerMessageId = Integer.valueOf(request.getParameter("managerMessageId")).intValue();
        boolean bool = managerServiceI.RemoveMessage(managerMessageId);
        if (bool) {
            return "success";
        } else {
            return "false";
        }
    }

    /**
     * 　　* @param modelAndView request
     * 　　* @return ModelAndView
     * 　　* @author：千夜
     * 　　* @date 2019/4/30 9:51
     * 　 * @description: TODO:查看用户相关信息
     */
    @RequestMapping("checkUser")
    public ModelAndView checkUser(ModelAndView modelAndView, HttpServletRequest request) {
        Integer userId = Integer.valueOf(request.getParameter("userId")).intValue();
        modelAndView.addObject("userId",userId);
        /**************************分页获取相关参数************************************/
        String Page = request.getParameter("PcurrentPage");
        Integer currentPage;
        if (null != Page) {
            currentPage = Integer.valueOf(Page).intValue();
        } else {
            currentPage = 1;
        }
        pojo.Page page = new Page();
        page.setLimitNumber(20);
        page.setCurrentPage(currentPage);
        System.out.println(currentPage);
        PageReturn pageReturn = new PageReturn();
        page = pageReturn.ReturnPage(page);//填充page实体
        Integer locationPage = currentPage;
        modelAndView.addObject("PcurrentPage", locationPage);
        /*************************************************************************/
        /**************************分页获取相关参数************************************/
        String Page1 = request.getParameter("CcurrentPage");
        Integer currentPage1;
        if (null != Page1) {
            currentPage1 = Integer.valueOf(Page).intValue();
        } else {
            currentPage1 = 1;
        }
        pojo.Page page1 = new Page();
        page1.setLimitNumber(20);
        page1.setCurrentPage(currentPage1);
        PageReturn pageReturn1 = new PageReturn();
        page1 = pageReturn.ReturnPage(page1);//填充page实体
        Integer locationPage1 = currentPage1;
        modelAndView.addObject("CcurrentPage", locationPage1);
        /*************************************************************************/
        /**************************分页获取相关参数************************************/
        String Page2 = request.getParameter("AcurrentPage");
        Integer currentPage2;
        if (null != Page2) {
            currentPage2 = Integer.valueOf(Page).intValue();
        } else {
            currentPage2 = 1;
        }
        pojo.Page page2 = new Page();
        page2.setLimitNumber(20);
        page2.setCurrentPage(currentPage2);
        PageReturn pageReturn2 = new PageReturn();
        page2 = pageReturn.ReturnPage(page2);//填充page实体
        Integer locationPage2 = currentPage2;
        modelAndView.addObject("AcurrentPage", locationPage2);
        /*************************************************************************/
        /**************************分页获取相关参数************************************/
        String Page3 = request.getParameter("OcurrentPage");
        Integer currentPage3;
        if (null != Page3) {
            currentPage3 = Integer.valueOf(Page).intValue();
        } else {
            currentPage3 = 1;
        }
        pojo.Page page3 = new Page();
        page3.setLimitNumber(20);
        page3.setCurrentPage(currentPage3);
        PageReturn pageReturn3 = new PageReturn();
        page3 = pageReturn.ReturnPage(page3);//填充page实体
        Integer locationPage3 = currentPage3;
        modelAndView.addObject("OcurrentPage", locationPage3);
        /*************************************************************************/
        String whichPage = request.getParameter("whichPage");
        if (whichPage == null || whichPage == "") {
            modelAndView.addObject("whichPage", "publish");
        } else {
            modelAndView.addObject("whichPage", whichPage);
        }
        /**********************获取发表文章列表**************************/
        List<Essay> essaylist = essayServiceI.ShowUsersEssay(userId, page);
        Integer essaylistsize = essayServiceI.ShowUsersEssayCount(userId);//发表的文章数量
        /**********************获取收藏文章列表************************************/
        List<Integer> collectionlist = collectionServiceI.FindEssayId(userId, page1);
        List<Essay> collectionEssayList = new ArrayList<Essay>();
        for (Integer essayId : collectionlist) {
            Essay essay = essayServiceI.FindEssay(essayId);
            collectionEssayList.add(essay);
        }
        Integer collectionEssayListSize = collectionServiceI.FindEssayIdCount(userId);
        /***********************获取关注用户列表*************************************/
        List<Integer> attentionlist = attentionServiceI.FindAttentionUser(userId, page2);
        List<User> attentionUserList = new ArrayList<User>();
        for (Integer user2 : attentionlist) {
            User user3 = userServiceI.FindUserById(user2);
            attentionUserList.add(user3);
        }
        Integer attentionUserListSize = attentionServiceI.FindAttentionUserCount(userId);
        /***********************获取我的下载文章刘表*************************************/
        List<Integer> obtainList = obtainServiceI.FindEssay(userId, page3);
        List<Essay> obtainEssayList = new ArrayList<Essay>();
        for (Integer integer : obtainList) {
            Essay essay = essayServiceI.FindEssay(integer);
            obtainEssayList.add(essay);
        }
        Integer obtainEssayListSize = obtainServiceI.FindEssayCount(userId);


        modelAndView.addObject("obtainEssayList", obtainEssayList);//下载文章列表
        modelAndView.addObject("obtainEssayListSize", obtainEssayListSize);//下载文章数量
        modelAndView.addObject("collectionEssayList", collectionEssayList);//收藏文章列表
        modelAndView.addObject("collectionEssayListSize", collectionEssayListSize);//收藏文章数量
        modelAndView.addObject("essaylistsize", essaylistsize);//发表文章列表
        modelAndView.addObject("essaylist", essaylist);//发表文章数量
        modelAndView.addObject("attentionUserListSize", attentionUserListSize);//关注用户列表
        modelAndView.addObject("attentionUserList", attentionUserList);//关注用户数量

        modelAndView.setViewName("/community/jsp/manager/checkUser");
        return modelAndView;
    }

    /**
     * 　　* @param modelandview  request
     * 　　* @return modelandview
     * 　　* @author：千夜
     * 　　* @date 2019/5/7 11:04
     * 　 * @description: TODO：查看用户信息
     */
    @RequestMapping("checkUserInfo")
    public ModelAndView checkUserInfo(ModelAndView modelAndView, HttpServletRequest request) {
        Integer userId = Integer.valueOf(request.getParameter("userId")).intValue();
        User user = userServiceI.FindUserById(userId);
        modelAndView.addObject("user", user);
        modelAndView.setViewName("/community/jsp/manager/checkUserInfo");
        return modelAndView;
    }

    @RequestMapping("deleteUser")
    @ResponseBody
    public String deleteUser(HttpServletRequest request) {
        Integer userId = Integer.valueOf(request.getParameter("userId")).intValue();
        try {
            userServiceI.DeleteById(userId);
        } catch (Exception e) {
            e.printStackTrace();
            return "false";
        }
        return "success";
    }

    @RequestMapping("resetPassword")
    public String resetPassword() {
        return "/community/jsp/manager/resetPassword";
    }

    @RequestMapping("confirmPass")
    @ResponseBody
    public String confirmPass(HttpServletRequest request) {
        Manager manager1 = (Manager) request.getSession().getAttribute("manager");
        Integer managerId = manager1.getManagerId();
        String password = request.getParameter("password");
        Manager manager = new Manager();
        manager.setPassword(password);
        manager.setManagerId(managerId);
        boolean bool = managerServiceI.ResetPassword(manager);
        if (bool) {
            return "success";
        } else
            return "false";
    }

    @RequestMapping("test")
    @ResponseBody
    public List<EssayAndUser> test() {
        /*  List<EssayAndUser> list = essayServiceI.FindManagerViewEssay();*/
        return null;
    }
}
